// Ofri Keidar 302933981 group 05

package controller;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * Class represents an object sent between client and server. The Message object holds client's query and
 * parameters for the query. The Message can hold the query's result as well.
 * The class is serializable in order to be sent through a socket
 */
public class Message implements Serializable {

	private static final long serialVersionUID = -2328726146271378701L; // serial number
	
	// query names
	public static final String ADD_BUILDINGS = "add buildings";
	public static final String GET_VACANT_FLATS = "get vacant flats";
	public static final String GET_VACANT_FLATS_BY_ROOM = "get vacant flats by room number";
	public static final String GET_VACANT_FLATS_BY_ROOM_AND_ADDRESS = "get vacant flats by room number and adress";
	public static final String GET_FLATS_BY_ADDRESS = "get flats by adress";
	public static final String GET_ALL_FLATS = "get all flats";
	public static final String GET_ALL_PENTHOUSES = "get all penthouses";
	public static final String GET_ALL_GARDEN_APARTMENTS = "get all garden apartments";
	public static final String GET_VACANT_APARTMENTS_NUM = "get vacant apartments number";
	public static final String GET_VACANT_APARTMENTS_NUM_BY_ADDRESS = "get vacant apartments number by address";
	public static final String UPDATE_RESIDENT = "update resident";
	public static final String NUMERIC_VALUE = "numeric value";
	public static final String BOOLEAN_VALUE = "boolean value";
	
	// query parameter names
	public static final String NUM_OF_ROOMS = "room number";
	public static final String ST_NAME = "street name";
	public static final String BLD_NUMBER = "building number";
	public static final String APARTMENT_NUMBER = "apartment number";
	public static final String NEW_RESIDENT_NAME = "new resident name";
	
	private String query; // client's query name
	private Map<String, String> parameters; // parameters to send (can be query's result as well)
	private List < Map<String, String> > multipleParameters; // parameters collection to send (can be query's result as well) 
	
	/**
	 * Constructor- creates a new message, holding given query and parameters
	 * @param query- query name
	 * @param parameters- parameters to send
	 * @param multipleParameters- parameters collection to send
	 */
	public Message(String query, Map<String, String> parameters, List<Map<String, String>> multipleParameters) {
		
		// set members according to given values
		this.query = query;
		this.parameters = parameters;
		this.multipleParameters = multipleParameters;
	}
	
	/**
	 * Constructor- creates a new message, holding given query and parameters.
	 * The parameters collection is initialized as an empty list
	 * @param query- query name
	 * @param queryParameters- parameters to send
	 */
	public Message(String query, Map<String, String> queryParameters) {
		
		// set members according to given values
		this.query = query;
		this.parameters = queryParameters;
		this.multipleParameters = new LinkedList<Map<String,String>>();
	}

	/**
	 * Returns query name
	 * @return query attribute
	 */
	public String getQuery() {
		return query;
	}

	/**
	 * Returns query's parameters
	 * @return parameters attribute
	 */
	public Map<String, String> getParameters() {
		return parameters;
	}
	
	/**
	 * Returns parameters collection
	 * @return parameters collection attribute
	 */
	public List < Map<String, String> > getMultipleParameters() {
		return multipleParameters;
	}
}